<!-- resources/templates/fragments/header.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻分析系统</title>
</head>
<body>
<header th:fragment="header">
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" th:href="@{/}">新闻分析系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/news}">新闻列表</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="categoryDropdown" role="button"
                           data-bs-toggle="dropdown" aria-expanded="false">
                            新闻分类
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="categoryDropdown">
                            <li><a class="dropdown-item" th:href="@{/news/category/政治}">政治</a></li>
                            <li><a class="dropdown-item" th:href="@{/news/category/经济}">经济</a></li>
                            <li><a class="dropdown-item" th:href="@{/news/category/科技}">科技</a></li>
                            <li><a class="dropdown-item" th:href="@{/news/category/体育}">体育</a></li>
                            <li><a class="dropdown-item" th:href="@{/news/category/娱乐}">娱乐</a></li>
                            <li><a class="dropdown-item" th:href="@{/news/category/教育}">教育</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown" sec:authorize="isAuthenticated()">
                        <a class="nav-link dropdown-toggle" href="#" id="analysisDropdown" role="button"
                           data-bs-toggle="dropdown" aria-expanded="false">
                            新闻分析
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="analysisDropdown">
                            <li><a class="dropdown-item" th:href="@{/analysis}">分析概览</a></li>
                            <li><a class="dropdown-item" th:href="@{/analysis/category}">类别分析</a></li>
                            <li><a class="dropdown-item" th:href="@{/analysis/sentiment}">情感分析</a></li>
                            <li><a class="dropdown-item" th:href="@{/analysis/keyword}">关键词分析</a></li>
                            <li><a class="dropdown-item" th:href="@{/analysis/hot}">热度分析</a></li>
                        </ul>
                    </li>
<!--                    <li class="nav-item dropdown" sec:authorize="hasRole(\'ADMIN\')">-->
                        <li class="nav-item dropdown" sec:authorize="hasRole('ADMIN')">
<!--                    <li ... sec:authorize="hasRole('ADMIN')"> ... </li>    -->
                        <a class="nav-link dropdown-toggle" href="#" id="adminDropdown" role="button"
                           data-bs-toggle="dropdown" aria-expanded="false">
                            后台管理
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="adminDropdown">
                            <li><a class="dropdown-item" th:href="@{/admin/dashboard}">管理仪表盘</a></li>
                            <li><a class="dropdown-item" th:href="@{/admin/news}">新闻管理</a></li>
                            <li><a class="dropdown-item" th:href="@{/admin/users}">用户管理</a></li>
                            <li><a class="dropdown-item" th:href="@{/admin/crawler}">爬虫管理</a></li>
                        </ul>
                    </li>
                </ul>

                <!-- 搜索框 -->
                <form class="d-flex mx-auto" th:action="@{/news/search}" method="get">
                    <input class="form-control me-2" type="search" name="keyword" placeholder="搜索新闻..." aria-label="Search">
                    <button class="btn btn-outline-light" type="submit">搜索</button>
                </form>

                <div class="navbar-nav">
                    <div sec:authorize="isAuthenticated()">
                        <div class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                               data-bs-toggle="dropdown" aria-expanded="false">
                                <span sec:authentication="name"></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                                <li><a class="dropdown-item" href="#">个人资料</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li>
                                    <form th:action="@{/logout}" method="post">
                                        <button class="dropdown-item" type="submit">退出登录</button>
                                    </form>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div sec:authorize="!isAuthenticated()">
                        <a class="nav-link" th:href="@{/login}">登录</a>
                        <a class="nav-link" th:href="@{/register}">注册</a>
                    </div>
                </div>
            </div>
        </div>
    </nav>
</header>
</body>
</html>
